﻿@{
    ViewData["Title"] = "Home Page";

    DataTable userTable = ViewData["userTable"] as DataTable;
}
<!--
    html  table 毛坯 展示数据内容
    css   style 装修  修师页面
-->


<button id="btn_add">新建</button>
<table class="tz_table tz_w100 tz_mt5">
    <thead>
        <tr>
            <th>Id</th>
            <th>姓名</th>
            <th>性别</th>
            <th>年龄</th>
            <th>操作</th>
        </tr>
    </thead>
    <tbody>
        @for (int i = 0; i < userTable.Rows.Count; i++)
        {
            <tr>
                <td>@userTable.Rows[i]["id"]</td>
                <td>@userTable.Rows[i]["name"]</td>
                <td>@userTable.Rows[i]["gender"]</td>
                <td>@userTable.Rows[i]["age"]</td>
                <td>
                    <a href="/home/edit?id=@(userTable.Rows[i]["id"])">编辑</a>
                    <a href="javascript:deleteUser('@(userTable.Rows[i]["id"])')">删除</a>
                </td>
            </tr>
        }
    </tbody>
</table>

<script>
    $("#btn_add").click(function () { 
        window.location.href = "/home/add";
    });

    var deleteUser=function(id){
        if (!confirm("是否删除用户")) {
            return;
        }

        $.ajax({
            url: "/home/dodelete?id="+id,
            type: "POST",
            dataType: "JSON",
            contentType: "application/json; charset=utf-8",
            success: function (d) {
                alert(d.message);
                window.location.href = "/";
            },
            error: function (err) {

            }
        });
    }




</script>